<template>
  <div class="content">
    <el-form inline>
      <el-form-item label="品牌名称">
        <el-input
          v-model="query.brand"
          size="mini"
          placeholder="请输入品牌名称"
          clearable
        ></el-input>
      </el-form-item>
      <el-form-item label="型号">
        <el-input
          v-model="query.model"
          size="mini"
          placeholder="请输入型号"
          clearable
        ></el-input>
      </el-form-item>
      <!-- <el-form-item label="入库时间">
        <el-date-picker
          type="date"
          placeholder="选择日期"
          v-model="query.storageTime"
          value-format="yyyy-MM-dd"
          size="mini"
          :picker-options="pickerOptions0"
        ></el-date-picker>
      </el-form-item> -->
      <el-form-item>
        <el-button size="mini" type="primary" @click="getSearch"
          >查询</el-button
        >
      </el-form-item>
    </el-form>
    <el-table
      :data="sensorClassList"
      size="small"
      :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }"
      class="el-table-box"
      stripe
    >
      <el-table-column label="序号" type="index" width="80"> </el-table-column>
      <el-table-column prop="name" label="名称"></el-table-column>
      <el-table-column prop="brand" label="品牌"></el-table-column>
      <el-table-column prop="model" label="型号"></el-table-column>
      <el-table-column prop="reserve" label="库存"></el-table-column>
      <el-table-column prop="location" label="存放地点"></el-table-column>
      <el-table-column prop="remark" label="备注"></el-table-column>
    </el-table>
    <el-row type="flex" justify="end">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.page"
        :page-sizes="[10, 15]"
        :page-size="query.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-row>
  </div>
</template>

<script>
// import { getSensorClassByPage } from "../../../api/help";
import { getSpareMterialsList ,getSpareTatal} from "../../../api/help";

export default {
  name: "RescueMaterialManagement",
  props: {
    node: Object,
  },
  data() {
    return {
      // pickerOptions0: {
      //   disabledDate(time) {
      //     return time.getTime() > Date.now(); //如果没有后面的-8.64e6就是不可以选择今天的
      //   },
      // },

      query: {
        page: 1,
        pagesize: 10,
        brand: "",
        model: "",
      },
      total: 0,
      sensorClassList: [],
    };
  },
  mounted() {
    this.getSpareMterialsList();
  },
  methods: {
    async getSpareTatal() {
      const res = await getSpareTatal();
      if (res.resultCode == "200") {
        this.total = res.parameter;
      } else {
        this.total = 0;
      }
    },
    async getSpareMterialsList() {
      const res = await getSpareMterialsList({
        page: this.query.page - 1,
        pageSize: this.query.pagesize,
        tailingPondId: sessionStorage.getItem("sensorId"),
      });
      if (res.resultCode == "200") {
        this.sensorClassList = res.parameter.list;
        this.getSpareTatal();
      } else {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.sensorClassList = [];
        this.total = 0;
      }
    },
    // 监听 pagesize 改变的事件
    handleSizeChange(val) {
      this.query.pagesize = val;
      this.getSpareMterialsList();
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(val) {
      this.query.page = val;
      this.getSpareMterialsList();
    },
    async getSearch() {
      const res = await getSpareMterialsList({
        searchBrand: this.query.brand,
        searchModel: this.query.model,
        page: this.query.page - 1,
        pageSize: this.query.pagesize,
        tailingPondId: sessionStorage.getItem("sensorId"),
        // storageTime: this.query.storageTime,
      });
      console.log(res);
      if (res.resultCode == "200") {
        this.$message.success({
          message: "成功查询数据",
          offset: 400,
          duration: 1000,
        });
        this.sensorClassList = res.parameter.list;
        this.getSpareTatal();
      } else {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.sensorClassList = [];
        this.total = 0;
      }
    },
  },
};
</script>

<style scoped>
.content {
  padding: 0.1rem;
  font-size: 0.01rem;
}
.el-table {
  margin-bottom: 0.15rem;
  display: block;
  height: 63vh;
  overflow: auto;
  text-align: center;
}
.el-table::before {
  z-index: inherit;
}
</style>